<?php
class startup {

    public function __construct() {
        // Error Reporting
        error_reporting(E_ALL);

        // Check Version
        if (version_compare(phpversion(), '5.1.0', '<') == true) {
            exit('PHP5.1+ Required');
        }

        // Register Globals
        if (ini_get('register_globals')) {
                
            session_set_cookie_params(0, '/');
            session_start();
            
            $globals = array($_REQUEST, $_SESSION, $_SERVER, $_FILES);

            foreach ($globals as $global) {
                foreach(array_keys($global) as $key) {
                    unset(${$key}); 
                }
            }
        }

        // Magic Quotes Fix
        if (ini_get('magic_quotes_gpc')) {
            
            $_GET = clean($_GET);
            $_POST = clean($_POST);
            $_REQUEST = clean($_REQUEST);
            $_COOKIE = clean($_COOKIE);
        }

        if (!ini_get('date.timezone')) {
            date_default_timezone_set('UTC');
        }

        // Windows IIS Compatibility  
        if (!isset($_SERVER['DOCUMENT_ROOT'])) { 
            if (isset($_SERVER['SCRIPT_FILENAME'])) {
                $_SERVER['DOCUMENT_ROOT'] = str_replace('\\', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0 - strlen($_SERVER['PHP_SELF'])));
            }
        }

        if (!isset($_SERVER['DOCUMENT_ROOT'])) {
            if (isset($_SERVER['PATH_TRANSLATED'])) {
                $_SERVER['DOCUMENT_ROOT'] = str_replace('\\', '/', substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0 - strlen($_SERVER['PHP_SELF'])));
            }
        }

        if (!isset($_SERVER['REQUEST_URI'])) { 
            $_SERVER['REQUEST_URI'] = substr($_SERVER['PHP_SELF'], 1); 
            
            if (isset($_SERVER['QUERY_STRING'])) { 
                $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; 
            } 
        }

        if (!isset($_SERVER['HTTP_HOST'])) {
            $_SERVER['HTTP_HOST'] = getenv('HTTP_HOST');
        }
    }

    private function clean($data) {
        if (is_array($data)) {
            foreach ($data as $key => $value) {
                $data[clean($key)] = clean($value);
            }
        } else {
            $data = stripslashes($data);
        }
    
        return $data;
    }			

}
?>
